SHELL = /bin/sh
PKGCONFIG_LIBS = x11 gl glu
CPP = g++
CPPFLAGS = -std=c++0x -D_ICECODE_GRAPHICS -fPIC $(shell pkg-config --cflags $(PKGCONFIG_LIBS))
LD = g++
LDFLAGS = $(shell pkg-config --libs $(PKGCONFIG_LIBS))
LIB_NAME = icecode-graphics
LIB_FILENAME = lib$(LIB_NAME).so
OBJECTS = XConnection.o Window.o
LIB_VERSION = 0.1

.PHONY: clean install help pkg-config

all: $(LIB_FILENAME) pkg-config

$(LIB_FILENAME): $(OBJECTS)
	$(LD) -shared $(OBJECTS) -o $(LIB_FILENAME) $(LDFLAGS)

$(OBJECTS): %.o: %.cpp
	$(CPP) -c -o $@ $(CPPFLAGS) $<

clean:
	$(RM) $(OBJECTS) $(LIB_FILENAME) $(LIB_NAME).pc

install:
	@echo Not yet implemented.

help:
	@echo "targets: all clean install pkg-config help"
	@echo -e "\tall: makes everything\n\tclean: removes non-source files"
	@echo -e "\thelp: shows this message\n\tinstall: installs the compiled files"
	@echo -e "\tpkg-config: creates the pkg-config related files"

pkg-config:
	$(SHELL) ./compile_pkg-config.sh "$(LIB_VERSION)" "$(LIB_NAME)"
